package com.yu.mall.configuration;

import com.yu.mall.service.OrderConfirmService;
import com.yu.mall.service.ProductService;
import com.yu.mall.util.JDUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;

@Configuration
@EnableScheduling
@Slf4j
public class ScheduleConfiguration {

    @Resource
    ProductService productService;

    @Autowired
    private OrderConfirmService orderConfirmService;

    /**
     * 每一小时刷新JDtoken
     */
    @Scheduled(cron = "0 0 */1 * * ?")
    private void accessToken() {
        JDUtils.flushToken();
    }

    /**
     * 每30秒确认失败订单
     */
    @Scheduled(cron = "0/30 * * * * ?")
    private void synOrderConfirm() {
        orderConfirmService.synOrderConfirm();
    }

    /**
     * 每30秒同步完成订单
     */
    @Scheduled(cron = "0/30 * * * * ?")
    private void synOrderComplete() {
        orderConfirmService.synOrderComplete();
    }

    /**
     * 每5秒取消未确认订单
     */
    @Scheduled(cron = "0/5 * * * * ?")
    private void cancelOrderComplete() {
        orderConfirmService.cancelOrderComplete();
    }

    /**
     * 每天00：10获取所有商品
     */
    @Scheduled(cron = "0 30 23 * * ?")
    private void getProducts1() {
        productService.taskForGetAll1();
    }
    
    /**
     * 每小时同步退款消息
     */
    @Scheduled(cron = "50 0 */1 * * ?")
    private void synOrderTuiKuan() {
        orderConfirmService.synOrderTuiKuan();
    }
    
    /**
     * 每小时同步申请单环节变更消息消息
     */
    @Scheduled(cron = "0 0 */1 * * ?")
    private void synOrderChange() throws Exception{
        orderConfirmService.synOrderChange();
    }

    /**
     * 每分钟同步拆单消息
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    private void synOrderId() throws Exception{
        orderConfirmService.synOrderId();
    }

    /**
     * 每分钟同步退款中消息
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    private void synReturning() throws Exception{
        orderConfirmService.synReturning();
    }
    
    /**
     * 每分钟同步支付中消息
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    private void synPaying() throws Exception{
        orderConfirmService.synPaying();
    }

    /**
     * 每分钟同步拆单消息
     */
    /*@Scheduled(cron = "0 0/1 * * * ?")
    private void synOrderIdNew() throws Exception{
        orderConfirmService.synOrderIdNew();
    }*/
}